home *** CD-ROM | disk | FTP | other *** search
/ Tech Arsenal 1 / Tech Arsenal (Arsenal Computer).ISO / tek-04 / adg_1_3.zip / DLG-OPTS.C < prev    next >
C/C++ Source or Header  |  1991-02-21  |  5KB  |  168 lines

  1. /****************************************************************************
  2. Module name: Dlg-Opts.C
  3. Programmer : Jeffrey M. Richter.
  4. *****************************************************************************/
  5.  
  6. #include "..\nowindws.h"
  7. #undef NOCOLOR
  8. #undef NOCTLMGR
  9. #undef NOKERNEL
  10. #undef NOMSG
  11. #undef NOSHOWWINDOW
  12. #undef NOUSER
  13. #undef NOWINMESSAGES
  14. #undef NOWINOFFSETS
  15. #undef NOWINSTYLES
  16. #include <windows.h>
  17.  
  18. #include <stdlib.h>
  19.  
  20. #include "dlg-opts.h"
  21.  
  22. extern HANDLE _hInstance;
  23.  
  24.  
  25. // Turns a style ON for a window.
  26. #define SetWindowStyle(hWnd, Style) \
  27.    SetWindowLong(hWnd, GWL_STYLE, Style | GetWindowLong(hWnd, GWL_STYLE));
  28.  
  29. // Turns a style OFF for a window.
  30. #define ResetWindowStyle(hWnd, Style) \
  31.    SetWindowLong(hWnd, GWL_STYLE, ~Style & GetWindowLong(hWnd, GWL_STYLE));
  32.  
  33.  
  34. #define ENABLECHILDREN  (0x80000000L)
  35. #define DISABLECHILDREN (0x00000000L)
  36.  
  37. BOOL FAR PASCAL EnableChildrenInOptionArea (HWND hWnd, LONG lParam);
  38.  
  39.  
  40. void FAR PASCAL ShowArea (BOOL fShowDefAreaOnly, HWND hDlg, HWND hWndDefArea) {
  41.    FARPROC fpProc;
  42.    RECT rcDlg, rcDefArea;
  43.    char szDlgDims[25];
  44.  
  45.    // Save original width and height of dialog box.
  46.    GetWindowRect(hDlg, &rcDlg);
  47.  
  48.    // Retrieve coordinates for default area window.
  49.    GetWindowRect(hWndDefArea, &rcDefArea);
  50.  
  51.    // Disable controls outside of default area.  Any window whose
  52.    //   left edge > rcDefArea.right || right > rcDefArea.bottom
  53.    fpProc = MakeProcInstance(EnableChildrenInOptionArea, _hInstance);
  54.    EnumChildWindows(hDlg, fpProc,
  55.       (fShowDefAreaOnly ? DISABLECHILDREN  : ENABLECHILDREN) |
  56.       MAKELONG(rcDefArea.right, rcDefArea.bottom));
  57.    FreeProcInstance(fpProc);
  58.  
  59.    if (fShowDefAreaOnly) {
  60.       wsprintf(szDlgDims, "%05u %05u",
  61.          rcDlg.right - rcDlg.left, rcDlg.bottom - rcDlg.top);
  62.  
  63.       ResetWindowStyle(hWndDefArea, SS_BLACKRECT);
  64.       SetWindowStyle(hWndDefArea, SS_LEFT);
  65.       SetWindowText(hWndDefArea, szDlgDims);
  66.  
  67.       // Resize dialog box to fit only default area.
  68.       SetWindowPos(hDlg, NULL, 0, 0, 
  69.          rcDefArea.right - rcDlg.left, rcDefArea.bottom - rcDlg.top,
  70.          SWP_NOZORDER | SWP_NOMOVE);
  71.  
  72.       // Make sure that the Default area box is hidden.
  73.       ShowWindow(hWndDefArea, SW_HIDE);
  74.  
  75.    } else {
  76.       GetWindowText(hWndDefArea, szDlgDims, sizeof(szDlgDims));
  77.  
  78.       // Restore dialog box to its original size.
  79.       SetWindowPos(hDlg, NULL, 0, 0, 
  80.          atoi(szDlgDims), atoi(szDlgDims + 6),
  81.          SWP_NOZORDER | SWP_NOMOVE);
  82.    }
  83. }
  84.  
  85.  
  86. BOOL FAR PASCAL EnableChildrenInOptionArea (HWND hWnd, LONG lParam) {
  87.    RECT rc;
  88.    BOOL fEnable = (lParam & ENABLECHILDREN) != 0;
  89.    lParam &= ~ENABLECHILDREN;
  90.  
  91.    // Calculate rectangle occupied by child window in screen coordinates.
  92.    GetWindowRect(hWnd, &rc);
  93.  
  94.    // NOTE: Right  edge of "Default area" window is in LOWORD(lParam)
  95.    //       Bottom edge of "Default area" window is in HIWORD(lParam)
  96.  
  97.    // Enable/Disable child if its:
  98.    //    right  edge is >= the right  edge of hWndDefArea.
  99.    //    bottom edge is >= the bottom edge of hWndDefArea.
  100.    if ((rc.right  >= (int) LOWORD(lParam)) ||
  101.        (rc.bottom >= (int) HIWORD(lParam)))
  102.       EnableWindow(hWnd, fEnable);
  103.  
  104.    // Allow enumeration to continue until all windows are checked.
  105.    return(1);
  106. }
  107.  
  108. #ifdef _DEMO
  109. //****************************************************************************
  110. // Functions for the ModalLess Dialog Box Demonstration.
  111.  
  112. #include "dialog.h"
  113.  
  114. BOOL FAR PASCAL OptionsDlgProc (HWND hDlg, WORD wMsg, WORD wParam, LONG lParam) {
  115.    BOOL fProcessed = TRUE;
  116.  
  117.    switch (wMsg) {
  118.  
  119.       case WM_INITDIALOG:
  120.          // During initialization, before any windows are shown, resize the
  121.          // dialog box so that only the "default" portion is shown.
  122.          ShowArea(TRUE, hDlg, GetDlgItem(hDlg, ID_DEFAULTBOX));
  123.          break;
  124.  
  125.       case WM_COMMAND:
  126.          switch (wParam) {
  127.  
  128.             case IDOK:
  129.             case IDCANCEL:
  130.                // Terminate dialog box if user selects the "Ok" or 
  131.                // "Cancel" buttons.
  132.                EndDialog(hDlg, wParam);
  133.                break;
  134.  
  135.             case ID_OPTIONS:
  136.                if (HIWORD(lParam) != BN_CLICKED)
  137.                   break;
  138.  
  139.                // User selected "Options >>" button, show entire dialog box.
  140.                ShowArea(FALSE, hDlg, GetDlgItem(hDlg, ID_DEFAULTBOX));
  141.  
  142.                // The ShowArea(FALSE, ...) function enables all windows 
  143.                // outside the "default" area.  Any windows that should be 
  144.                // disabled, must be made explicitly disabled here.  Note, 
  145.                // the status of the windows within the "default" area is 
  146.                // NOT changed.
  147.  
  148.                // Set the focus to the desired control.
  149.                SetFocus(GetNextDlgTabItem(hDlg, LOWORD(lParam), 0));
  150.  
  151.                // Disable "Options>>" button.
  152.                EnableWindow(LOWORD(lParam), FALSE);
  153.                break;
  154.  
  155.             default:
  156.                fProcessed = FALSE;
  157.                break;
  158.          }
  159.          break;
  160.  
  161.       default:
  162.          fProcessed = FALSE;
  163.          break;
  164.    }
  165.    return(fProcessed);
  166. }
  167. #endif
  168.